﻿#ifndef __AF_ANIMATION_H__
#define __AF_ANIMATION_H__

#include "AF_Define.h"

namespace AF
{
	_INTERFACE AnimationResponse;
	class Animation; //-* Runnable
}
typedef AF::AnimationResponse		AF_IAnimationResponse;
typedef AF::Animation			AF_CAnimation;

namespace AF
{
	enum AnimationState
	{
		AS_STOP,
		AS_PLAY,
		AS_RUN,
		AS_PAUSE,
	};
}
typedef AF::AnimationState		AF_EAnimationState;
#define AF_AS_STOP			AF::AS_STOP
#define AF_AS_PLAY			AF::AS_PLAY
#define AF_AS_RUN			AF::AS_RUN
#define AF_AS_PAUSE			AF::AS_PAUSE

#include "AF_Timer.h"
#include "AF_Bundle.h"

namespace AF
{
	class _TEMPORARY Graphics;

	/// 动画效果响应处理接口
	_INTERFACE AnimationResponse
	{
	public:
		/// 当动画效果响应时
		virtual void		OnAnimationResponse(AF_CAnimation* pAnimation, AF_EAnimationState as) = 0;
	};

	/// 动画效果控制基类
	class _ABSTRACT Animation : public Runnable
	{
	private:
		static UINT		GetID();
		static UINT		m_nID;

	public:
		Animation();
		virtual ~Animation();

	public:
		/// 运行动画效果
		void			Play(Bundle* pParam = NULL);
		/// 暂停动画效果
		void			Pause();
		/// 停止动画效果
		bool			Stop();
		/// 精确计时
		void			ExactTimer();

		/// 设置响应处理类
		void			SetResponse(AnimationResponse* pResponse);
		/// 设置动画效果间隔时间
		void			SetInterval(TimeTicks ttInterval);
	protected:
		/// 当运行动画效果时
		virtual bool		OnPlay(Bundle* pParam)
					{return true;}
		/// 当更新动画效果时
		virtual bool		OnUpdate()		// 返回：是否继续运行
					{return false;}
		/// 当暂停动画效果时
		virtual bool		OnPause()
					{return true;}
		/// 当停止动画效果时
		virtual bool		OnStop()
					{return true;}

	private:
		void			OnRun(RunBase* pRunBase);

	public:
		/// 名字属性
		DIM_ATTRIB_R(_STRING, AnimationName);
		/// 绑定的可绘制对象属性
		DIM_ATTRIB(AF::Graphics*, HostGraphics);
		/// 动画效果状态属性
		DIM_ATTRIB_R(AF::AnimationState, State);
		/// 循环属性
		DIM_ATTRIB(bool, Loop);

	public:
		void			SetAnimationName(_STRING strAnimationName);

	protected:
		AnimationResponse*	m_pResponse;
		Timer*			m_pTimer;
		TimeTicks		m_ttInterval;

	private:
		bool			m_isExactTimer;

	};
}

#endif